*Paper: Fiscal Rules, Corruption and Electoral Accountability - Replication Files

*NB: the version of rdrobust is: "version 9.1.0  2022-10-28" 
*which rdrobust

clear all
cap log close 
set more off


**Global files
global folder "/Users/tommasogiommoni/Dropbox/Determinants of corruption/Stability pact and corruption/Replication files JOP"


********************************************************************************
****----						Dataset open 					    	----**** 
********************************************************************************

use "$folder/Data/dataset_feb2024.dta", clear

**-- Global

global controls7 proportion_female_Elected_lag av_education_Elected_lag av_age_Elected_lag  victory_margin_lag term_limit_lag 
global covs_bandwidth anno_FE* 
global FE_regres anno id_provincia
global control_set $controls7 education_mayor_lag age_mayor_lag gender_mayor_lag
global cluster_regr codcom 

**-- Panel dataset

xtset codcom anno
fvset base 2012 anno

**-- Additional cleaning

keep  if population_anagrafe<10000

foreach i in 200 300 400 600 800 900 1000 1200 1400 1500 1600{

local pop=5000+(`i')

display `pop'

gen	P_pl`i'=population_anagrafe_DSP-`pop'
gen	S_pl`i'=(population_anagrafe_DSP<=`pop') 
gen	PS_pl`i' = P_pl`i'*S_pl`i'
gen	PT_pl`i' = P_pl`i'*T
gen	ST_pl`i' = S_pl`i'*T
gen	PST_pl`i'= P_pl`i'*S_pl`i'*T
}

foreach i in 200 300 400 600 800 900 1000 1200 1400 1500 1600{

local pop=5000-(`i')

display `pop'

gen	P_min`i'=population_anagrafe_DSP-`pop'
gen	S_min`i'=(population_anagrafe_DSP<=`pop') 
gen	PS_min`i' = P_min`i'*S_min`i'
gen	PT_min`i' = P_min`i'*T
gen	ST_min`i' = S_min`i'*T
gen	PST_min`i'= P_min`i'*S_min`i'*T
}

********************************************************************************
****----						Analysis 					    		----**** 
********************************************************************************

****---- Analysis ----****

foreach i in 200 300 400 600 800 900 1000 1200 1400 1500 1600{

  capture drop  Scorruption_PC*  Scorruption_exp_log* Bcorruption_PC*  Bcorruption_exp_log*
  capture drop band* sample* 

  foreach var in corruption_PC  corruption_exp_log{

qui rdrobust `var' P_pl`i' if population_anagrafe<10000 & anno>2012 & FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA") , covs() 
local band1=e(h_l)
qui rdrobust `var' P_pl`i' if population_anagrafe<10000 & anno<2013 & FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA") , covs() 
local band2=e(h_l)
local band=(`band1'+`band2')/2
display "`band'"
gen	B`var'=(`band1'+`band2')/2
gen S`var' = abs(P_pl`i')<B`var'

}

qui reghdfe corruption_PC_sd S_pl`i' P_pl`i' T ST_pl`i' PT_pl`i' PS_pl`i' PST_pl`i' $control_set if Scorruption_PC==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab1_pl`i'
qui reghdfe corruption_exp_log_sd S_pl`i' P_pl`i' T ST_pl`i' PT_pl`i' PS_pl`i' PST_pl`i' $control_set if Scorruption_exp_log==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab2_pl`i'

}


foreach i in 200 300 400 600 800 900 1000 1200 1400 1500 1600{

  capture drop  Scorruption_PC*  Scorruption_exp_log* Bcorruption_PC*  Bcorruption_exp_log*
  capture drop band* sample* 

  foreach var in corruption_PC  corruption_exp_log{

qui rdrobust `var' P_min`i' if population_anagrafe<10000 & anno>2012 & FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA") , covs() 
local band1=e(h_l)
qui rdrobust `var' P_min`i' if population_anagrafe<10000 & anno<2013 & FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA") , covs() 
local band2=e(h_l)
local band=(`band1'+`band2')/2
display "`band'"
gen	B`var'=(`band1'+`band2')/2
gen S`var' = abs(P_min`i')<B`var'

}

qui reghdfe corruption_PC_sd S_min`i' P_min`i' T ST_min`i' PT_min`i' PS_min`i' PST_min`i' $control_set if Scorruption_PC==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab1_min`i'
qui reghdfe corruption_exp_log_sd S_min`i' P_min`i' T ST_min`i' PT_min`i' PS_min`i' PST_min`i' $control_set if Scorruption_exp_log==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab2_min`i'

}

****---- Table ----****

esttab tab1_pl200 tab1_min200 tab1_pl400 tab1_min400 tab1_pl600 tab1_min600 tab1_pl800 tab1_min800  using "$folder/Tables/TableA19_A.tex", compress keep(ST*) se r2 staraux collabels(, none) ml(,none) cells(b(star fmt (%9.3f)) se(par)) star(* 0.10 ** 0.05 *** 0.01) replace
esttab tab2_pl200 tab2_min200 tab2_pl400 tab2_min400 tab2_pl600 tab2_min600 tab2_pl800 tab2_min800  using "$folder/Tables/TableA19_B.tex", compress keep(ST*) se r2 staraux collabels(, none) ml(,none) cells(b(star fmt (%9.3f)) se(par)) star(* 0.10 ** 0.05 *** 0.01) replace




